using System;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;
using Headspring.Training.Core.Model;
using Headspring.Training.Core.Services;
using Headspring.Training.UI.Presenters;
using StructureMap;

namespace Headspring.Training.UI.Views
{
	public partial class Layout : ViewMasterPage, ILayoutView
	{
		private string _version;

		protected string Version
		{
			get { return _version; }
		}

		public Employee CurrentUser { get; set; }

		public void AddFlashMessage(FlashMessage message)
		{
			var panel = new Panel();
			if (message.Type == FlashMessage.MessageType.Message)
			{
				panel.CssClass = "flash message";
			}
			else if (message.Type == FlashMessage.MessageType.Error)
			{
				panel.CssClass = "flash error";
			}

			panel.Controls.Add(new LiteralControl(message.Message));
			flash.Controls.Add(panel);
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			var presenter = ObjectFactory.FillDependencies<LayoutPresenter>();
			presenter.Execute(this);

			var information = ObjectFactory.GetInstance<IApplicationInformation>();
			_version = information.ProductVersion;
		}
	}
}